﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using NUnit.Framework;
using Rhino.Mocks;
using SimpleServiceBus.Bus;
using SimpleServiceBus.Bus.MessageManagement.MessageHandling;
using SimpleServiceBus.Bus.Pipeline;
using SimpleServiceBus.Bus.Pipeline.PipelineComponents;
using SimpleServiceBus.Tests.Stubs;

namespace SimpleServiceBus.Tests.Bus.Pipeline.PipelineComponents
{
    [TestFixture]
    public class MessageHandlerDispatcherComponentTestFixture
    {
        [Test]
        public void Will_Call_Dispatch_On_Dispatch_Service()
        {
            var comp = new MessageHandlerDispatcherComponent();
            var pipeline = MockRepository.GenerateStub<IMessagePipeline>();
            var env = new MessageEnvelope { Body = "Hello" };
            var context = new ServiceLocatorOnlyMessageContext();
            
            var dispatcher = MockRepository.GenerateStub<IMessageDispatcher>();
            context.RegisterService<IMessageDispatcher>(dispatcher);

            pipeline.Stub(action => action.CurrentContext).Return(context);
            dispatcher.Stub(action => action.Dispatch(env, context));

            comp.Pipeline = pipeline;
            comp.ProcessMessage(env);

            dispatcher.AssertWasCalled(action=>action.Dispatch(env,context));
        }
    }
}
